package org.birtserver.frontend.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.birtserver.backend.service.reports.ReportService;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class HTMLReportServlet extends HttpServlet {

  private static final long serialVersionUID = -1735229972936276030L;
  
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    
    ApplicationContext context = 
      WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
    
    response.setContentType("text/html");
    
    String reportIds = request.getParameter("reportId");
    if (reportIds == null) {
      
      response.getOutputStream().write("Parameter reportId is not specified!".getBytes());
      return;
      
    } else {
      
      ReportService reportService = (ReportService)context.getBean("reportService", ReportService.class);
      reportService.outputReportContent(new Long(reportIds), response.getOutputStream());
      
    }
     
  }
  
  
}
